package cn.line5.seam.db;

import java.math.BigDecimal;
import java.util.Date;

/**
 * <h1>数据库参数类</h1>
 * 
 * @author Liu,Xiaojun
 * @since JDK1.6
 */
public class Parameter {
	private Integer logo;

	private Object object;

	private ParameterType type;

	/**
	 * 构造方法
	 * 
	 * @param logo
	 *            参数序号，从1开始
	 * @param val
	 *            参数
	 * @param type
	 *            参数类型
	 */
	public Parameter(Integer logo, Object val, ParameterType type) {
		this.logo = logo;
		this.object = val;
		this.type = type;
	}

	/**
	 * 构造方法，根据参数类型自动确定参数类型。
	 * 
	 * @param logo
	 *            参数序号，从1开始
	 * @param val
	 *            参数
	 */
	public Parameter(Integer logo, Object val) {
		ParameterType type = ParameterType.String;
		if (val instanceof String) {
			type = ParameterType.String;
		} else if (val instanceof Date) {
			type = ParameterType.Date;
		} else if (val instanceof Integer) {
			type = ParameterType.Integer;
		} else if (val instanceof Long) {
			type = ParameterType.Long;
		} else if (val instanceof Double) {
			type = ParameterType.Double;
		} else if (val instanceof Float) {
			type = ParameterType.Float;
		} else if (val instanceof Short) {
			type = ParameterType.Short;
		} else if (val instanceof Byte) {
			type = ParameterType.Byte;
		} else if (val instanceof BigDecimal) {
			type = ParameterType.BigDecimal;
		} else if (val instanceof Boolean) {
			type = ParameterType.Boolean;
		} else {
			type = ParameterType.String;
		}
		this.logo = logo;
		this.object = val;
		this.type = type;
	}

	/**
	 * 获取参数序号
	 */
	public Integer getLogo() {
		return logo;
	}

	/**
	 * 获取参数
	 */
	public Object getObject() {
		return object;
	}

	/**
	 * 获取参数类型
	 */
	public ParameterType getType() {
		return type;
	}

	public String toString() {
		return String.valueOf(logo);
	}
}
